<!doctype html>
<html xmlns:th="http://www.w3.org/1999/xhtml">

<head >
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <style>
        html,
        body,
        table,
        #container {
            width: 100%;
            height: 100%;
        }
        .amap-icon img {
            width: 25px;
            height: 34px;
        }
    </style>
    <title>圆的绘制和编辑</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="/css/plugins/jsTree/style.min.css" rel="stylesheet">
    <link href="/css/plugins/jqTreeGrid/jquery.treegrid.css"
          rel="stylesheet">
    <link href="/css/plugins/summernote/summernote-0.8.8.css"
          rel="stylesheet">
</head>
<body>
<table>
    <tr>
        <td  style="width: 20%" valign="top">
            <div class="col-sm-3">
                <div class="ibox ibox-body">
                    <div class="ibox-title">
                        <h5>选择部门</h5>
                    </div>
                    <div class="ibox-content">
                        <div id="jstree"></div>
                    </div>
                </div>
            </div>
        </td>
        <td>
            <div id="container" ></div>

        </td>
    </tr>
</table>
<div ></div>
<div th:include="include :: footer"></div>
<script type="text/javascript" src="/js/appjs/contract/map/realTime.js"></script>
<link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
<script src="https://webapi.amap.com/maps?v=1.4.14&key=34f702bfabb9ec6c25ade58d26cb9030&plugin=AMap.CircleEditor"></script>
<script src="https://a.amap.com/jsapi_demos/static/demo-center/js/demoutils.js"></script>
<script type="text/javascript">
    var map = null;
    function createMap(center) {
        map = new AMap.Map('container', {
            zoom: 20,
            center: center,
            resizeEnable: true
        });
        log.success("创建地图成功");
    }
    $('#jstree').on("changed.jstree", function(e, data) {
        if (data.selected != -1) {
            if(data.node.original.hasChildren == false){
                /*根据id获取地理位置*/
                var userid = data.selected[0];
                $.ajax({
                    type : "post",
                    url : "/contract/site/getRealUserSite",
                    data : {
                        'userId' : userid
                    },
                    success : function(data) {
                        if(data.dept != ""){
                            var jw = "["+data.dept.longitude+","+data.dept.latitude+"]";
                            var center = eval("("+ jw+")");
                            createMap(center);

                            marker = new AMap.Marker({
                                position: center,
                                icon: '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png',
                                offset: new AMap.Pixel(-13, -30)
                            });
                            marker.setLabel({
                                offset: new AMap.Pixel(20, 20),  //设置文本标注偏移量
                                content: "<div class='info'>" +
                                    data.user+"  "+
                                    data.date
                                    +"</div>", //设置文本标注内容
                                direction: 'right' //设置文本标注方位
                            });
                            marker.setMap(map);
                        }
                    }
                });
            }
        }
    });
</script>
</body>
</html>